﻿CREATE proc [dbo].[NKNH_ThemPhieuGui_H]    
@bien int,  
@so_ctu nvarchar(255),      
@tk_no nvarchar(255),    
@chitiet_tkno nvarchar(255), 

@loai_tien nvarchar(255),    
@ty_gia float,    
@soctgoc nvarchar(255),    
@hoten nvarchar(255),    
@noidung nvarchar(255),    
@tk_vat nvarchar(255),    
@tien_vat float,    
@mauso nvarchar(255),    
@khautru bit,    
@ngay_ctu datetime,    
@thang datetime,  
@bophan nvarchar(255)    
    
    
as    
if exists(select * from NKNH_H Where so_ctu =@so_ctu  )   
  
  
begin    
select ErrCode=0    
end    
else    
if (@bien=1)  
begin    
    
 insert into NKNH_H(so_ctu,ngay_ctu,tk_no,loai_tien,chitiet_tkno,tk_co,chitiet_tkco,ty_gia,soctgoc,hoten,noi_dung,tk_vat,tien_vat,mauso,khautru,thang,bophan)    
   values(@so_ctu,@ngay_ctu,@tk_no,@loai_tien,@chitiet_tkno,null,null,@ty_gia,@soctgoc,@hoten,@noidung,@tk_vat,@tien_vat,@mauso,@khautru,@thang,@bophan)    
 select ErrCode=1    
end    
else if(@bien=2)  
begin   
insert into NKNH_H(so_ctu,ngay_ctu,tk_no,loai_tien,chitiet_tkno,tk_co,chitiet_tkco,ty_gia,soctgoc,hoten,noi_dung,tk_vat,tien_vat,mauso,khautru,thang,bophan)    
   values(@so_ctu,@ngay_ctu,null,@loai_tien,null,@tk_no,@chitiet_tkno,@ty_gia,@soctgoc,@hoten,@noidung,@tk_vat,@tien_vat,@mauso,@khautru,@thang,@bophan)    
 select ErrCode=1    
end  
  
--select*from NKNH_L    
--select*from NKNH_H